package com.crb.crm.manage.excel.listener;

import com.crb.crm.manage.excel.ExcelTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * Package: com.crb.crm.manage.excel
 * Description：
 * Author: huangjian
 * Date:  2020/9/4 17:07
 * Modified By:
 *
 * @author huangjian
 */
@Slf4j
@Component
public class ExcelListenerCtx  {

    @Autowired
    private List<BaseExcelListener> excelListenerList;

    public BaseExcelListener chooseOne(ExcelTemplate byTemplateCode){
        Optional<BaseExcelListener> first = excelListenerList.stream().filter(item -> byTemplateCode.equals(item.support())).findFirst();
        if(first.isPresent()){
            return first.get();
        }
        throw new IllegalArgumentException("渠道不支持");
    }
}
